package thread;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: liuliwei
 * Date: 2017-09-27
 * Time: 下午3:31
 * Description: ${description}
 */
public class ThreadTest {


    public static void main(String[] args) {
        UnsafeSequence unsafeSequence = new UnsafeSequence();

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int i=0;
                List<Integer> list = Lists.newArrayList();
                while (i++ < 10) {
                    int value = unsafeSequence.getValue();
                    list.add(value);
//                    System.out.println(value+Thread.currentThread().toString());;
                }
                System.out.println(list+Thread.currentThread().toString());
            }
        };

        Thread thread = new Thread(runnable);
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        thread.start();
        thread1.start();
        thread2.start();
    }
}


class UnsafeSequence {
    private int value;

    public int getValue() {
        return value++;
    }
}
